package com.itheima.exerciseTest.test30_39;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Test38 {
    public static void main(String[] args) {
        // Stream流

        // 单列集合
        // method1();

        // 双列集合
        // method2();

        // 数组
        // method3();

        // 多个相同数据的多个数据
        // method4();

        List<String> list = new ArrayList<>(List.of("aaa","bbb","c","ddd","aa"));
        list.stream().filter(s -> s.length()==3).forEach(s -> System.out.println(s));


        list.stream().filter(
                new Predicate<String>() {
                    @Override
                    public boolean test(String s) {
                        return s.length()==3;
                    }
                }
        ).forEach(
                new Consumer<String>() {
                    @Override
                    public void accept(String s) {
                        System.out.println(s);
                    }
                }
        );
    }


    private static void method4() {
        Stream.of(1,2,3,4,5).forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });
    }

    private static void method3() {
        int[] arr = {1,2,3,4,5};
        Arrays.stream(arr).forEach(s-> System.out.println(s));
    }

    private static void method2() {
        Map<String, Integer> map = new HashMap<>(Map.ofEntries(
                Map.entry("张三", 23),
                Map.entry("李四", 24),
                Map.entry("王五", 25)
        ));
        map.entrySet().stream().forEach(s -> System.out.println(s));

        map.keySet().stream().forEach(s -> System.out.println(s + "=" + map.get(s)));
    }

    private static void method1() {
        List<String> al = new ArrayList<>(List.of("aaa", "bbb", "ccc"));
        al.stream().forEach(s -> System.out.println(s));
    }
}
